import { receiveCoupon, getReceiveCoupon, getCouponByMemberId, getCouponByCanUse, getCouponByAlreadyUse, getCouponByOutTime } from '@/api/coupon/coupon'

const state = {
  // userKey: getUserKey()
}

const mutations = {

}

const actions = {
  receiveCoupon({ commit }, couponId) {
    return new Promise((resolve, reject) => {
      receiveCoupon(couponId)
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  },
  getReceiveCoupon({ commit }) {
    return new Promise((resolve, reject) => {
      getReceiveCoupon()
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  },
  getCouponByMemberId({ commit }, query) {
    return new Promise((resolve, reject) => {
      getCouponByMemberId(query)
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  },
  getCouponByCanUse({ commit }) {
    return new Promise((resolve, reject) => {
      getCouponByCanUse()
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  },
  getCouponByAlreadyUse({ commit }) {
    return new Promise((resolve, reject) => {
      getCouponByAlreadyUse()
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  },
  getCouponByOutTime({ commit }) {
    return new Promise((resolve, reject) => {
      getCouponByOutTime()
        .then(response => {
          resolve(response)
        }).catch(error => {
        reject(error)
      })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
